/**
    初始化 公司信息

**/

(function(vc){
    vc.extends({
        data:{
            step:1,
            companyInfo:{
                name: "",
                shopName:'',
                areaAddress: '',
                address: "",
                tel: "",
                storeTypeCd: "800900000005",
                nearbyLandmarks: "无",
                areaCode:'',
                shopType:'',
                acceptTerms:false,
            },
			acceptTerms: false
        },
         _initMethod:function(){
             //$that.initStoreType();
         },
         _initEvent:function(){
            vc.on('company','notifyCompanyInfo',function(_data){
                vc.copyObject(_data,$that.companyInfo);
            });
            vc.on('company','notifyCompanyReadme',function(_data){
                vc.copyObject(_data,$that.companyInfo);
            })
              
         },
        methods:{
            next:function(){
                //校验字段是否填写
                if($that.step<2){
                    $that.step = $that.step+1;
                }
            },
            previous:function(){
                if($that.step>1){
                    $that.step = $that.step-1;;
                }
            },
			
			// 验证勾选 “同意条款”
			validateAcceptTerms: function(){
				return vc.validate.validate({
				    companyInfo: $that.companyInfo
				}, {
                    'companyInfo.name': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "公司名不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "100",
                            errInfo: "公司名长度必须在100位之内"
                        },
                    ],
                    'companyInfo.areaAddress': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "请选择地址"
                        }
                    ],
                    'companyInfo.address': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "地址不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "200",
                            errInfo: "地址长度必须在200位之内"
                        },
                    ],
                    'companyInfo.tel': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "手机号不能为空"
                        },
                        {
                            limit: "phone",
                            param: "",
                            errInfo: "不是有效的手机号"
                        }
                    ],
                    'companyInfo.storeTypeCd': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "商户类型不能为空"
                        }
                    ],
                    'companyInfo.nearbyLandmarks': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "附近建筑不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "200",
                            errInfo: "地址长度必须在200位之内"
                        }
                    ],
				    'companyInfo.acceptTerms': [
				        {
				            limit: "required",
				            param: "",
				            errInfo: "请阅读须知并勾选确认"
				        },
				    ],
				});
			},
			
            finish:function(){
				// 验证勾选 “同意条款”
				if(!$that.validateAcceptTerms() ){
                    vc.toast(vc.validate.errInfo);
					return;
				}
                if( !$that.companyInfo.acceptTerms){
                    vc.toast("未选择 我同意并遵守以上信息");
					return;
				}
                //这里写提交代码
                vc.http.apiPost(
                            '/shop.pcReplenishStoreAndShop',
                            JSON.stringify($that.companyInfo),
                            {
                                emulateJSON:true
                             },
                             function(json,res){
                                //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                                let _json = JSON.parse(json)
                                if(_json.code == 0){
                                    vc.jumpToPage("/");
                                    return ;
                                }
                               vc.toast(_json.msg);
                             },
                             function(errInfo,error){
                                console.log('请求失败处理');
                                $that.companyInfo.errorInfo = errInfo;
                             });

            }
        }

    });

})(window.vc);

